import {createRouter, createWebHistory} from "vue-router";
import Layout from '@/layout/index.vue'


/**
 * 常驻路由
 */
export const constantRoutes = [
    {
        path: '/login',
        component: () => import("../pages/login/login.vue"),
    },
    {
        path: '/register',
        component: () => import("../pages/login/register.vue"),
    },
]

/**
 * 需要权限匹配的路由
 */
export const DynamicRoutes = [
    {
        path: '/home',
        component: Layout,
        // redirect: '/home/home',
        children: [
            {
                path: '/home',
                name: 'home',
                meta: {
                    title: '首页',
                    elIcon: 'HomeFilled',
                },
                component: () => import("../views/home/index.vue"),
            }
        ]
    },
    {
        path: "/user",
        component: Layout,
        meta: {
            title: '个人中心',
            icon: ['user','#fff',13],
        },
        children: [
            {
                path: "updatePwd",
                component: () => import("../views/user/updatePwd.vue"),
                meta: {
                    title: "修改密码",
                    icon: "icon-name",
                }
            },
            {
                path: "user",
                component: () => import("../views/user/userInfo.vue"),
                meta: {
                    title: "用户信息",
                    icon: "icon-name",
                }
            }
        ]
    },
    {
        path: "/userMan",
        component: Layout,
        meta: {
            title: '用户管理',
            elIcon: 'Menu',
            role: ['admin']
        },
        children: [
            {
                path: "/userMan",
                component: () => import("../views/userMan/userMan.vue"),
                meta: {
                    title: "用户管理",
                    elIcon: 'Menu',
                }
            },
        ]
    },
    {
        path: "/:pathMatch(.*)*",
        meta: {
            title: "找不到此页面",
        },
        redirect: '/login',
        // component: () => import("../pages/error/404.vue"),
    },
];


const router = createRouter({
    history: createWebHistory(),
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
});

export default router;
